package org.dcarew.clearcase;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * 
 * 
 * @author Devon Carew
 */
class DatFileInfo
{
    private String viewName;
    
    
    DatFileInfo(File datFile)
    {
        try
        {
            parse(datFile);
        }
        catch (IOException ce)
        {
            // TODO:
            
            ce.printStackTrace();
        }
    }
    
    public String getViewName()
    {
        return viewName;
    }
    
    private void parse(File datFile)
        throws IOException
    {
        BufferedReader reader = new BufferedReader(new FileReader(datFile));
        
        reader.readLine();
        reader.readLine();
        
        String line = reader.readLine();
        
        parseFileEntry(line);
        
        reader.close();
    }
    
    private void parseFileEntry(String line)
    {
        // 2|fa0238db466e4ac28c2672fcf98a8253|a:Windows XP|1c:Wed Nov 04 10:01:24 PST 2009|ucm|3c:http://alnrtnl1.aln.experian.com:12080/TeamWeb/services/Team|1c:A03189a_GVAPMAIN_NG_COMMON_2|1bfd
        
        // 0=? type
        // 1=?
        // 2=? os name
        // 3=? last mod date? created date?
        // 4=?
        // 5=? url
        // 6=view name
        // 7=?
        
        String[] params = line.split("\\|");
        
        viewName = ccParseString(params[6]);
    }

    private String ccParseString(String str)
    {
        if (str.indexOf(":") != -1)
            str = str.substring(str.indexOf(":") + 1);
        
        return str;
    }

}
